#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define gc() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=gc();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        x*=f;
    }
}
using namespace IO;
const int N=1e6+5;
int n,C,a[N],w[N<<1],idx;
#define ll long long
struct Tree{ll tag1,tag2,cov,lv;}t[1<<21];
inline void ins1(int p,ll v){t[p].tag1+=v,t[p].lv+=v;}
inline void ins2(int p,ll v,int l){t[p].tag2+=v,t[p].lv+=v*w[l];}
inline void ins3(int p,ll v){t[p].tag1=t[p].tag2=0;t[p].cov=t[p].lv=v;}
#define mid ((l+r)>>1)
inline void pushdown(int p,int l,int r){
	if(t[p].cov){
		ins3(2*p,t[p].cov);
		ins3(2*p+1,t[p].cov);
		t[p].cov=0;
	}
	if(t[p].tag1){
		ins1(2*p,t[p].tag1);
		ins1(2*p+1,t[p].tag1);
		t[p].tag1=0;
	}
	if(t[p].tag2){
		ins2(2*p,t[p].tag2,l);
		ins2(2*p+1,t[p].tag2,mid+1);
		t[p].tag2=0;
	}
}
#define ls 2*p,l,mid
#define rs 2*p+1,mid+1,r
void change1(int p,int l,int r,int rt,int v){
	if(r<=rt) return ins1(p,v),void();
	pushdown(p,l,r);
	change1(ls,rt,v);
	if(mid<rt) change1(rs,rt,v);
	t[p].lv=t[2*p].lv;
}
void change2(int p,int l,int r,int lt,int v){
	if(lt<=l) return ins1(p,v),ins2(p,1,l),void();
	pushdown(p,l,r);
	if(lt<=mid) change2(ls,lt,v);
	change2(rs,lt,v);
	t[p].lv=t[2*p].lv;
}
void cover(int p,int l,int r,int lt,int rt,ll v){
	if(lt<=l&&r<=rt) return ins3(p,v),void();
	pushdown(p,l,r);
	if(lt<=mid) cover(ls,lt,rt,v);
	if(mid<rt) cover(rs,lt,rt,v);
	t[p].lv=t[2*p].lv;
}
ll query(int p,int l,int r,int x){
	if(l==r) return t[p].lv;
	pushdown(p,l,r);
	return x<=mid?query(ls,x):query(rs,x);
}
int find(int p,int l,int r,ll v){
	if(l==r) return t[p].lv<=v?l:l-1;
	pushdown(p,l,r);
	if(t[2*p+1].lv<=v) return find(rs,v);
	return find(ls,v);
}

int main(){
	freopen("minimize.in","r",stdin);
	freopen("minimize.out","w",stdout);
	read(n),read(C);
	for(int i=1;i<=n;++i) read(a[i]),w[++idx]=a[i];
	sort(w+1,w+idx+1);
	idx=unique(w+1,w+idx+1)-w-1;
	for(int i=1;i<=n;++i){
		a[i]=lower_bound(w+1,w+idx+1,a[i])-w;
		change2(1,1,idx,a[i],-w[a[i]]);
		if(a[i]>1){
			ll val=query(1,1,idx,a[i]);
			int k=find(1,1,idx,val-C);
			if(k+1<a[i]) cover(1,1,idx,k+1,a[i]-1,val);
			if(k>=1) change1(1,1,idx,k,C);
		}
	}
	cout<<t[1].lv;
	return 0;
}


